﻿#include "label_485.h"


#include <QMessageBox>
#include <QMouseEvent>
#include "dialog_485_setting.h"


#pragma execution_character_set("utf-8")

Label485::Label485(QWidget* parent) : QLabel(parent) {
	this->setAlignment(Qt::AlignHCenter);
}


// 重写鼠标点击事件 mousePressEvent()
void Label485::mousePressEvent(QMouseEvent* event)
{
	//Qt::LeftButton
	//Qt::RightButton
	if (event->button() == Qt::LeftButton)
	{
		//QMessageBox::information(NULL, "单击", "单击了我", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

	//	Dialog485Setting dlg(this->toolTip());
	//	dlg.exec();
	}
}
// 重写鼠标事件处理 event()
bool Label485::event(QEvent* e)
{
	if (e->type() == QEvent::MouseButtonDblClick)
	{
		QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(e);
		if (mouseEvent->button() == Qt::LeftButton)
		{
			//QMessageBox::information(NULL, "单击", "单击了我", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
			QString s = this->objectName();
			int pos_1 = s.lastIndexOf('_');
			int port = s.mid(pos_1 + 1).toInt();


			QString b = this->parent()->objectName();

			int pos_2 = b.lastIndexOf('_');
			int board = b.mid(pos_2 + 1).toInt();

			if (board < 1 || board > 12)
			{
				return false;
			}

			Dialog485Setting dlg(port, board);
			dlg.exec();

			return true;
		}
	}
	return QLabel::event(e);
}
